package object.library.operation;

import object.library.Book;
import object.library.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("借书");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要借阅的图书编号：");
        int id = scanner.nextInt();
        if(id < 0 || id >= bookList.getSize()){
            System.out.println("图书编号不存在");
            return;
        }
        Book book = bookList.getBook(id);
        if(book.isBorrowed()){
            System.out.println("图书已被借出");
            return;
        }
        book.setBorrowed(true);
        System.out.println("图书借阅成功");
    }
}
